﻿using System;
using WSKnowledge.WSHelpers.DesignByContract;

namespace WSKnowledge.WSHelpers
{
	[Serializable]
	public abstract class BilingualLookup
	{
		private readonly long _id;
		private readonly string _descriptionEn;
		private readonly string _descriptionAr;

		public long Id { get { return _id; } }
		public string DescriptionEn { get { return _descriptionEn; } }
		public string DescriptionAr { get { return _descriptionAr; } }

		protected BilingualLookup(long id, string nameEn, string nameAr)
		{
			Check.Require(id > 0, "Invalid id.");
			Check.Require(nameEn.IsNotEmpty(), "Invalid english description.");
			Check.Require(nameAr.IsNotEmpty(), "Invalid arabic description.");

			_id = id;
			_descriptionEn = nameEn;
			_descriptionAr = nameAr;
		}

		protected bool Equals(BilingualLookup lookup)
		{
			if (ReferenceEquals(lookup, null)) return false;
			if (ReferenceEquals(lookup, this)) return true;
			return (Id == lookup.Id)
				   && (DescriptionEn == lookup.DescriptionEn)
				   && (DescriptionAr == lookup.DescriptionAr);
		}

		public override bool Equals(object obj)
		{
			return Equals(obj as BilingualLookup);
		}

		public override int GetHashCode()
		{
			return Hashing.RSHash(Id);
		}
	}

}
